﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElevatorSimCSharp
{
	public enum ElevatorState{
		ElevatorMoving,
		DoorOpening,
		DoorOpenPeopleEnter,
		DoorOpenPeopleExit,
		DoorClosing,
		Idle
	}
	
    class Elevator
    {
		bool doorOpen;
		ElevatorState state = ElevatorState.Idle;
        short currentFloor;
        short LastFloorToGoTo;
        byte numberOfPeopleInElevator;
        List<Person> peopleGoTo;
        sbyte goingWhichDirection;
        short maxFloor;
        short minFloor;
        byte maxPeopleInElevator;
		byte timerElevator;

        public Elevator(short floorStart, short maxFloor, short minFloor, byte maxPeopleInElevator)
        {
			doorOpen = false;
			peopleGoTo = new List<Person>();
            this.currentFloor = floorStart;
            this.goingWhichDirection = 0;
            this.maxFloor = maxFloor;
            this.minFloor = minFloor;
            this.maxPeopleInElevator = maxPeopleInElevator;
			time = 0;
        }

        public Elevator()
        {
			doorOpen = false;
            peopleGoTo = new List<Person>();
            currentFloor = 0;
            minFloor = 0;
            maxFloor = 0;
            maxPeopleInElevator = 20;
			timer = 0;
        }

		public static void incrementTime ()
		{
			timer ++
		}
		
		
		
		
        public List<Person> getPersonsList()
        {
            return peopleGoTo;
        }

        public void setPersonsList(List<Person> peopleList)
        {
            peopleGoTo = peopleList;
            // numberOfPeopleInElevator = (byte) peopleGoTo.Count;
        }

        public short getCurrentFloor()
        {
            return currentFloor;
        }

        public void initializeElevator(short floorStart, short maxFloor, short minFloor, byte maxPeopleInElevator)
        {
            this.currentFloor = floorStart;
            this.goingWhichDirection = 0;
            this.maxFloor = maxFloor;
            this.minFloor = minFloor;
            this.maxPeopleInElevator = maxPeopleInElevator;
        }

        public sbyte getDirection()
        {
            return goingWhichDirection;
        }

        public byte getMaxNumberOfPeople()
        {
            return maxPeopleInElevator;
        }

        public byte getNumberOfPeopleInElevator()
        {
            return numberOfPeopleInElevator;
        }

        public void incrementNumberOfPeopleInElevator()
        {
            numberOfPeopleInElevator++;
        }

        public void decrementNumberOfPeopleInElevator()
        {
            numberOfPeopleInElevator--;
        }

        public void moveElevator(short speed)
        {
            currentFloor += speed;
        }

        //public void incrementCurrentFloor(short speed)
        //{
        //    currentFloor += speed;
        //}

        //public void decrementCurrentFloor(short speed)
        //{
        //    currentFloor += speed;
        //}

        public short getLastFloorToGoTo()
        {
            return LastFloorToGoTo;
        }

        public void setLastFloorToGoTo(short lastFloorToGoTo)
        {
            this.LastFloorToGoTo = lastFloorToGoTo;
        }

        public void setDirection(sbyte direction)
        {
            this.goingWhichDirection = direction;
        }

        internal void addPerson(Person person)
        {
            peopleGoTo.Add(person);
        }

        internal void setMaxNumberOfPeople(byte maxNumber)
        {
            maxPeopleInElevator =  maxNumber;
        }
		
		public void setDoor(bool doorOpen) {
			this.doorOpen = doorOpen;
		}
		
		public bool getDoor() {
			return doorOpen;
		}
		
		public void setState(ElevatorState state) {
			this.state = state;
		}
		
		public ElevatorState getState() {
			return state;
		}
    }
}
